import { DisposeView } from "../../../mvc/core/DisposeView";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { CareerUtil } from "../common/util/CareerUtil";
import { Cache } from "../../cache/Cache";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LadderBattlefieldCareerButton } from "./renderer/LadderBattlefieldCareerButton";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class LadderBattlefieldApplyView
    
    export  class LadderBattlefieldApplyView extends DisposeView
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */onClickApplyBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var onClickHandler: Function;

            var loc1;
            onClickHandler = null;
            e = arg1;
            onClickHandler = (arg1: int): void
            {
                if (arg1 == Alert.YES) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LadderBattlefieldCareerApply, _selectCareer));
                }
                return;
            }
            if (this._selectCareer <= 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(28802));
                return;
            }
            Alert.show(Language.getStringByParam(28803, HTMLUtil.addColor(CareerUtil.getCareerName(this._selectCareer), CareerUtil.getCareerColorString(this._selectCareer))), null, Alert.YES | Alert.NO, null, onClickHandler);
            return;
        }

        /* internal  */onCareerSelectHandler(arg1: DataEvent): void
        {
            this._selectCareer = arg1.data as int;
            return;
        }

        public setApplyBtnEnabled(): void
        {
            var loc1=Cache.instance.ladderBattlefield.ladderCareer;
            if (this._isLoadCom) 
            {
                this._applyBtn.filterEnabled = !(loc1 > 0);
            }
            return;
        }

        /* internal  */onLoadResHandler(): void
        {
            this._isLoadCom = true;
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.LadderBattlefieldTxt4, 18, 120, this));
            this.setApplyBtnEnabled();
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            pushUIToDisposeVec(ObjCreate.createBg(0, 0, 425, 365, this));
            this._applyBtn = ObjCreate.createGLoadedButton(ResFileConst.LadderBattlefieldApplyBtn, 160, 308, 97, 42, this);
            this._applyBtn.configEventListener(flash.events.MouseEvent.CLICK, this.onClickApplyBtnHandler);
            pushUIToDisposeVec(ObjCreate.createBg(15, 105, 397, 2, this, ImagesConst.SplitLine));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28813), 10, 8, 220, 20, this, GlobalStyle._textFormat6));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28814), 10, 30, 400, 40, this, GlobalStyle.setTextFormatLeading(GlobalStyle._textFormat1, 5)));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28815), 10, 75, 220, 20, this, GlobalStyle._textFormat6));
            pushUIToDisposeVec(ObjCreate.createBg(15, 155, 400, 128, this, ImagesConst.FightingStrgBg));
            this._careerOne = new LadderBattlefieldCareerButton(Cache.instance.role.careerBasic);
            ObjCreate.setObjAttri(this._careerOne, 40, 165, -1, -1, this);
            this._careerTwo = new LadderBattlefieldCareerButton(Cache.instance.role.careerSecond);
            ObjCreate.setObjAttri(this._careerTwo, 240, 165, -1, -1, this);
            var loc1=ObjCreate.createGButton(Language.getString(28825), 364, -28, 62, 24, this);
            loc1.toolTipData = Language.getString(28833);
            pushUIToDisposeVec(loc1);
            LoaderHelp.addResCallBack(ResFileConst.LadderBattlefield, this.onLoadResHandler);
            Dispatcher.addEventListener(EventName.LadderBattlefieldCareerSelect, this.onCareerSelectHandler);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            this._applyBtn.dispose(arg1);
            DisplayUtil.removeMe(this._careerOne);
            DisplayUtil.removeMe(this._careerTwo);
            this._isLoadCom = false;
            this._applyBtn = null;
            this._careerOne = null;
            this._careerTwo = null;
            this._selectCareer = 0;
            Dispatcher.removeEventListener(EventName.LadderBattlefieldCareerSelect, this.onCareerSelectHandler);
            return;
        }

        /* internal */ /* var */_applyBtn: GLoadedButton;

        /* internal */ /* var */_careerOne: LadderBattlefieldCareerButton;

        /* internal */ /* var */_careerTwo: LadderBattlefieldCareerButton;

        /* internal */ /* var */_selectCareer: int;

        /* internal */ /* var */_isLoadCom: Boolean;
    }
